﻿using System;
using System.Data.Objects;

using OnlineFamilyCalendar.Data;
using OnlineFamilyCalendar.Model;

namespace OnlineFamilyCalendar.Test
{
    public class FakeOnlineFamilyCalendarEntities : IOnlineFamilyCalendarEntities
    {
        private FakeObjectSet<FamilyMember> _familyMember;
        private FakeObjectSet<LoginInformation> _loginInformation;

        public IObjectSet<FamilyMember> FamilyMember
        {
            get 
            { 
                return _familyMember ?? (_familyMember = new FakeObjectSet<FamilyMember>());
            }
            set
            {
                _familyMember = value as FakeObjectSet<FamilyMember>;
            }
        }

        public IObjectSet<LoginInformation> LoginInformation
        {
            get
            {
                return _loginInformation ?? (_loginInformation = new FakeObjectSet<LoginInformation>());
            }
            set
            {
                _loginInformation = value as FakeObjectSet<LoginInformation>;
            }
        }

        public int SaveChanges()
        {
            foreach (var loginInformation in LoginInformation)
            {
                ((IValidate)loginInformation).Validate(ChangeAction.Insert);
                ((IValidate)loginInformation).Validate(ChangeAction.Update);
                ((IValidate)loginInformation).Validate(ChangeAction.Delete);
            }

            foreach (var familyMember in FamilyMember)
            {
                ((IValidate)familyMember).Validate(ChangeAction.Insert);
                ((IValidate)familyMember).Validate(ChangeAction.Update);
                ((IValidate)familyMember).Validate(ChangeAction.Delete);
            }
            return 1;
        }

        public void Dispose()
        {
        }
    }
}
